﻿using MySchool;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyKTV
{
    public partial class xiugai_gequ : Form
    {
        DBHelper db = new DBHelper();
        DataSet set = new DataSet();

        public string geming ;
        
        public string pinsuo;
        public string gelei;
        public string geshou;
        public string geci;
        public string dizhi;

        string name;

        public xiugai_gequ()
        {
            InitializeComponent();
        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }


        //修改
        private void button2_Click(object sender, EventArgs e)
        {
            if (this.textBox4.Text==null)
            {
                MessageBox.Show("歌曲不能为空");
                if (name==this.textBox4.Text)
                {
                    MessageBox.Show("重复");
                    return;
                }
            }

            if (geming== this.textBox1.Text )
            {
                MessageBox.Show("重复");
                return;
            }

            db.OpenConnection();
            
            int one = 0;
            if (this.comboBox1.Text == "热门流行")
            {
                one = 1;
            }
            else if (this.comboBox1.Text == "经典老歌")
            {
                one = 2;
            }
            else if (this.comboBox1.Text == "影视金曲")
            {
                one = 3;
            }
            else if (this.comboBox1.Text == "游戏动漫")
            {
                one = 4;
            }
            else if (this.comboBox1.Text == "京剧戏曲")
            {
                one = 5;
            }
            else if (this.comboBox1.Text == "儿歌")
            {
                one = 6;
            }
            string sql1 = "";
            sql1 = "update song_info set song_name=N'" + this.textBox1.Text + "',song_ab=N'" + this.textBox2.Text + "',song_word_count='" + this.textBox3.Text + "',songtype_id='" + one + "',song_url=N'" + this.textBox4.Text + "',singer_id='" + this.comboBox2.SelectedValue.ToString() + "',song_play_count='" + this.textBox5.Text + "' where  song_name=N'" + geming  + "'";
            SqlCommand command = new SqlCommand(sql1, db.Connection);
            int coun = command.ExecuteNonQuery();
            if (coun>0)
            {

                MessageBox.Show("修改成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("修改失败");
                return;
            }
            
          
                
           
            db.CloseConnection();
        }

    



private void xiugai_gequ_Load(object sender, EventArgs e)
        {

            this.textBox1.Text = geming;
            this.textBox2.Text = pinsuo;
            this.comboBox1.Text = gelei;
            this.comboBox2.Text = geshou;
            this.textBox5.Text = geci;

            //初始歌曲类型

             db.OpenConnection();
            string sql = "select * from song_type";
            SqlCommand command = new SqlCommand(sql, db.Connection);
            SqlDataReader reader2 = command.ExecuteReader();
            while (reader2.Read())
            {
                this.comboBox1.Items.Add(reader2["songtype_name"]);
            }
            reader2.Close();
            db.CloseConnection();




            //初始歌手
            db.OpenConnection();
            string sql1 = "select * from singer_info";
            SqlDataAdapter command1 = new SqlDataAdapter(sql1, db.Connection);
            command1.Fill(set, "singer_info");
            //和下拉列表关联数据
            this.comboBox2.DataSource = set.Tables["singer_info"];
            //绑定实际值
            this.comboBox2.ValueMember = "singer_id";
            //绑定显示的值
            this.comboBox2.DisplayMember = "singer_name";
            db.CloseConnection();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            DialogResult result = fileDialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                string name = fileDialog.FileName.Substring(fileDialog.FileName.LastIndexOf("\\") + 1);
                Console.WriteLine(name);
                this.textBox4.Text = fileDialog.FileName;
            }
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            int i;
            i = this.textBox1.Text.Length;
            this.textBox3.Text = i.ToString();
        }
    }
}
